package com.sskj.api.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sskj.api.domain.CommunicationProtocol;
import com.sskj.api.service.ICommunicationProtocolService;
import com.sskj.api.vo.req.CommunicationProtocolPageListReq;
import com.sskj.common.util.ApiResponseUtil;
import com.sskj.common.vo.ApiResponse;
import com.sskj.common.vo.SimplePagination;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "通讯协议模块")
@RestController
@RequestMapping("/admin/communicationProtocol")
@Validated
public class CommunicationProtocolController {

    @Autowired
    private ICommunicationProtocolService communicationProtocolService;

    // 内部添加
//    @PostMapping("innerAdd")
//    public ApiResponse<Object> innerAdd(@Valid @RequestBody CommunicationProtocol communicationProtocol) {
//        communicationProtocolService.add(communicationProtocol);
//
//        return ApiResponseUtil.success();
//    }

    @Operation(summary = "更新通信协议")
    @PostMapping("update")
    public ApiResponse<Object> update(@Valid @RequestBody CommunicationProtocol communicationProtocol) {
        communicationProtocolService.update(communicationProtocol);

        return ApiResponseUtil.success();
    }

    @Operation(summary = "通信协议列表")
    @GetMapping("pageList")
    public ApiResponse<SimplePagination<CommunicationProtocol>> pageList(CommunicationProtocolPageListReq req) {
        IPage<CommunicationProtocol> communicationProtocolIPage = communicationProtocolService.pageList(req);

        return ApiResponseUtil.success(communicationProtocolIPage);
    }
}
